package com.modelo.dao.obradocumento;

import java.util.List;

import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Repository;

import com.modelo.dao.comun.HibernateBaseDAO;
import com.modelo.entity.ObraDocumento;

@Repository
public class ObraDocumentoDAO extends HibernateBaseDAO<ObraDocumento> implements IObraDocumentoDAO {
	public static final String ID_DOCUMENTO = "idDocumento";

	private static final Logger log = LoggerFactory.getLogger(ObraDocumentoDAO.class);

	public static ObraDocumentoDAO getFromApplicationContext(ApplicationContext ctx) {
		return (ObraDocumentoDAO) ctx.getBean("ObraDocumentoDAO");
	}

	@Autowired
	public ObraDocumentoDAO(SessionFactory sessionFactory) {
		super(sessionFactory);
	}

	public List<ObraDocumento> findByExample(ObraDocumento instance) {
		log.debug("finding ObraDocumento instance by example");
		try {
			List<ObraDocumento> results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: " + results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List<ObraDocumento> findByIdDocumento(Object idDocumento) {
		return findByProperty(ID_DOCUMENTO, idDocumento);
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding ObraDocumento instance with property: " + propertyName + ", value: "
				+ value);
		try {
			String queryString = "from ObraDocumento as model where model." + propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	@Override
	protected void initDao() {

	}
}